package com.github.shuaidd.service.mapper;

import com.github.shuaidd.model.repository.CommentEntityMapper;
import org.activiti.app.domain.runtime.Comment;
import org.activiti.engine.impl.cmd.AbstractCustomSqlExecution;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 描述
 *
 * @author ddshuai
 * @date 2020-07-20 22:45
 **/
@Service
public class CommentMapperService extends BaseMapperService implements CommentEntityMapper {

    @Override
    public int deleteByPrimaryKey(Long id) {
        return managementService.executeCustomSql(new AbstractCustomSqlExecution<CommentEntityMapper, Integer>(CommentEntityMapper.class) {
            @Override
            public Integer execute(CommentEntityMapper commentEntityMapper) {
                return commentEntityMapper.deleteByPrimaryKey(id);
            }
        });
    }

    @Override
    public int insert(Comment record) {
        return managementService.executeCustomSql(new AbstractCustomSqlExecution<CommentEntityMapper, Integer>(CommentEntityMapper.class) {
            @Override
            public Integer execute(CommentEntityMapper commentEntityMapper) {
                return commentEntityMapper.insert(record);
            }
        });
    }

    @Override
    public int insertSelective(Comment record) {
        return managementService.executeCustomSql(new AbstractCustomSqlExecution<CommentEntityMapper, Integer>(CommentEntityMapper.class) {
            @Override
            public Integer execute(CommentEntityMapper commentEntityMapper) {
                return commentEntityMapper.insertSelective(record);
            }
        });
    }

    @Override
    public Comment selectByPrimaryKey(Long id) {
        return managementService.executeCustomSql(new AbstractCustomSqlExecution<CommentEntityMapper, Comment>(CommentEntityMapper.class) {
            @Override
            public Comment execute(CommentEntityMapper commentEntityMapper) {
                return commentEntityMapper.selectByPrimaryKey(id);
            }
        });
    }

    @Override
    public int updateByPrimaryKeySelective(Comment record) {
        return managementService.executeCustomSql(new AbstractCustomSqlExecution<CommentEntityMapper, Integer>(CommentEntityMapper.class) {
            @Override
            public Integer execute(CommentEntityMapper commentEntityMapper) {
                return commentEntityMapper.updateByPrimaryKeySelective(record);
            }
        });
    }

    @Override
    public int updateByPrimaryKeyWithBLOBs(Comment record) {
        return managementService.executeCustomSql(new AbstractCustomSqlExecution<CommentEntityMapper, Integer>(CommentEntityMapper.class) {
            @Override
            public Integer execute(CommentEntityMapper commentEntityMapper) {
                return commentEntityMapper.updateByPrimaryKeyWithBLOBs(record);
            }
        });
    }

    @Override
    public int updateByPrimaryKey(Comment record) {
        return managementService.executeCustomSql(new AbstractCustomSqlExecution<CommentEntityMapper, Integer>(CommentEntityMapper.class) {
            @Override
            public Integer execute(CommentEntityMapper commentEntityMapper) {
                return commentEntityMapper.updateByPrimaryKey(record);
            }
        });
    }

    @Override
    public Long countByTaskId(String taskId) {
        return managementService.executeCustomSql(new AbstractCustomSqlExecution<CommentEntityMapper, Long>(CommentEntityMapper.class) {
            @Override
            public Long execute(CommentEntityMapper commentEntityMapper) {
                return commentEntityMapper.countByTaskId(taskId);
            }
        });
    }

    @Override
    public long countByProcessInstanceId(String processInstanceId) {
        return managementService.executeCustomSql(new AbstractCustomSqlExecution<CommentEntityMapper, Long>(CommentEntityMapper.class) {
            @Override
            public Long execute(CommentEntityMapper commentEntityMapper) {
                return commentEntityMapper.countByProcessInstanceId(processInstanceId);
            }
        });
    }

    @Override
    public List<Comment> findByTaskId(String taskId, String orderFormat) {
        return managementService.executeCustomSql(new AbstractCustomSqlExecution<CommentEntityMapper, List<Comment>>(CommentEntityMapper.class) {
            @Override
            public List<Comment> execute(CommentEntityMapper commentEntityMapper) {
                return commentEntityMapper.findByTaskId(taskId, orderFormat);
            }
        });
    }

    @Override
    public List<Comment> findByProcessInstanceId(String processInstanceId, String orderFormat) {
        return managementService.executeCustomSql(new AbstractCustomSqlExecution<CommentEntityMapper, List<Comment>>(CommentEntityMapper.class) {
            @Override
            public List<Comment> execute(CommentEntityMapper commentEntityMapper) {
                return commentEntityMapper.findByProcessInstanceId(processInstanceId, orderFormat);
            }
        });
    }

    @Override
    public int deleteAllByProcessInstanceId(String processInstanceId) {
        return managementService.executeCustomSql(new AbstractCustomSqlExecution<CommentEntityMapper, Integer>(CommentEntityMapper.class) {
            @Override
            public Integer execute(CommentEntityMapper commentEntityMapper) {
                return commentEntityMapper.deleteAllByProcessInstanceId(processInstanceId);
            }
        });
    }
}
